package com.bianmaba.dc.bean;

import lombok.Data;

import java.io.Serializable;
import java.util.*;

@Data
public class CollectionData implements Serializable {
    private String projectId;
    private String taskId;
    private String taskInstanceId;
    private String interfaceType;
    private List<Table> tables = new ArrayList<>(0);

    public static CollectionData of(String projectId, String taskId, String taskInstanceId, String interfaceType) {
        CollectionData datas = new CollectionData();
        datas.projectId = projectId;
        datas.taskId = taskId;
        datas.taskInstanceId = taskInstanceId;
        datas.interfaceType = interfaceType;
        return datas;
    }

    public static CollectionData of(String projectId, String taskId, String taskInstanceId, String interfaceType, List<Table> tables) {
        CollectionData datas = new CollectionData();
        datas.projectId = projectId;
        datas.taskId = taskId;
        datas.taskInstanceId = taskInstanceId;
        datas.interfaceType = interfaceType;
        datas.tables.addAll(tables);
        return datas;
    }

    public CollectionData addTable(Table table) {
        this.getTables().add(table);
        return this;
    }

    public CollectionData addTables(List<Table> tables) {
        this.getTables().addAll(tables);
        return this;
    }

    @Data
    public static class Table implements Serializable {
        private final List<Row> rows = new ArrayList(0);
        private String dataType;

        public Table() {
        }

        public static Table of(String dataType) {
            Table datas = new Table();
            datas.dataType = dataType;
            return datas;
        }

        public static Table of(String dataType, List<Row> rows) {
            Table datas = new Table();
            datas.dataType = dataType;
            datas.rows.addAll(rows);
            return datas;
        }

        public Table addRow(Row row) {
            this.getRows().add(row);
            return this;
        }

        public Table addRows(List<Row> rows) {
            this.getRows().addAll(rows);
            return this;
        }
    }


    @Data
    public static class Row implements Serializable {
        private Date startDate = new Date();
        private Date endDate = new Date();
        private Map<String, Object> datas = new HashMap<>(0);

        public static Row of(Map<String, Object> datas) {
            Row row = new Row();
            row.datas.putAll(datas);
            return row;
        }

        public static Row of(Date startDate, Date endDate) {
            Row row = new Row();
            row.startDate = startDate;
            row.endDate = endDate;
            return row;
        }

        public static Row of(Map<String, Object> datas, Date startDate, Date endDate) {
            Row row = new Row();
            row.startDate = startDate;
            row.endDate = endDate;
            row.datas.putAll(datas);
            return row;
        }

        public Row setEndDate(Date endDate) {
            this.endDate = endDate;
            return this;
        }

        public Row setStartDate(Date startDate) {
            this.startDate = startDate;
            return this;
        }

    }
}
